package com.example.demo.controller;

import com.example.demo.pojo.Dto.GoodsDto;
import com.example.demo.pojo.Goods;
import com.example.demo.service.GoodsService;
import com.example.demo.utill.ResponseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @RequestMapping("/findNew")
    @ResponseBody
    public List<GoodsDto> selectNew(){
        return goodsService.selectGoodsByParam("newest");
    }

    @RequestMapping("/findHot")
    @ResponseBody
    public List<GoodsDto> selectHot(){
        return goodsService.selectGoodsByParam("hot");
    }

    @RequestMapping("/findId")
    @ResponseBody
    public Goods selectId(int id){ return goodsService.selectGoodsById(id);}

    @RequestMapping("/selectByName")
    @ResponseBody
    public PageInfo<List<GoodsDto>> selectByName(@RequestParam(value = "name",required = false,defaultValue = "")String name,
                                                @RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
                                                @RequestParam(value = "pageSize",required = false,defaultValue = "15")int pageSize){
        return  goodsService.selectByName(name,pageNum,pageSize);
    }
}

